#include<iostream>
#include<cstring>
#include<unistd.h>
#include<signal.h>
void Printpending()
{
	sigset_t set;
	sigpending(&set);
	for(int signo=1;signo<=31;signo++)
	{
		if(sigismember(&set,signo))std::cout<<"1";
		else std::cout<<"0";
	}
	std::cout<<"\n";

}
void handler(int signo)
{
	//Printpending();
	std::cout<<"catch a signal,signal number:"<<signo<<std::endl;
	while(true)
	{
		Printpending();
		sleep(1);
	}
}
int main()
{
	struct sigaction act,oact;
	memset(&act,0,sizeof(act));
	memset(&oact,0,sizeof(oact));
	sigemptyset(&act.sa_mask);
	sigaddset(&act.sa_mask,1);
	sigaddset(&act.sa_mask,3);
	sigaddset(&act.sa_mask,4);
	act.sa_handler=handler;
	sigaction(2,&act,&oact);
	while(true)
	{
		std::cout<<"im a process:"<<getpid()<<std::endl;
		sleep(1);
	}
	return 0;

}

